package com.net.xpay.common.manager.impl.stat;

import com.google.common.base.Preconditions;
import com.net.xpay.common.manager.stat.PartnerUserRealTimeStatManager;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.stat.PartnerUserRealTimeStatMapper;
import com.net.xpay.common.domain.stat.PartnerUserRealTimeStat;
import com.net.xpay.common.model.PartnerUserSumModel;
import com.net.xpay.common.model.search.PartnerUserRealTimeStatSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class PartnerUserRealTimeStatManagerImpl extends AbstractManager<PartnerUserRealTimeStat> implements PartnerUserRealTimeStatManager {

    @Autowired
    private PartnerUserRealTimeStatMapper mapper;


    @Override
    protected BasicMapper<Long, PartnerUserRealTimeStat> getMapper() {
        return mapper;
    }

    @Override
    public PartnerUserRealTimeStat getByUserId(Long userId) {
        PartnerUserRealTimeStat condition = new PartnerUserRealTimeStat();
        condition.setUserId(userId);
        return getByCondition(condition);
    }

    @Override
    public List<PartnerUserRealTimeStat> search(PartnerUserRealTimeStatSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("total_trans_amount", "desc");
        page.addOrder("user_id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }




    @Override
    public long searchCount(PartnerUserRealTimeStatSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public PartnerUserSumModel aggSum(PartnerUserRealTimeStatSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.aggSum(searchModel);
    }


}
